package com.qf.redis.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

// 响应给前端的工具类
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {

    private Integer code;

    private String msg;

    private Object data;

    public static Result ok() {
        Result result = new Result();
        result.setCode(200);
        return result;
    }

    public static Result ok(Object data) {
        Result ok = ok();
        ok.setData(data);
        return ok;
    }

    public static Result error() {
        Result error = new Result();
        error.setCode(500);
        return error;
    }

    // 返回错误 并且有消息
    public static Result error(String msg) {
        Result error = error();
        error.setMsg(msg);
        return error;
    }
}
